<!-- 列表 -->
<template>
  <div class="list">
    <!-- 列表数据 -->
    <div class="ulist">
      <!-- 筛选头部 -->
      <!-- <div class="screen">
          <input-screen :placeholder='placeholder' @fromChild="getChildinput"></input-screen>
          <Select @fromChild="getChilddpthree"> </Select>
          <date-picker-one @fromChild="getChilddpone"></date-picker-one>
           <el-button type="primary" round @click="query" style="margin-left:2%;">查询</el-button>
      </div>-->
      <!-- 列表数据 -->
      <div class="list_data">
        <table-list :tableData="tableData" :listHeader="listHeader" @operate="operate" :type='type'></table-list>
        <!-- 分页 -->
        <div class="paging">
          <paging-list @Listdata="getChilddptwo" :addNum="addNum"></paging-list>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import inputScreen from '../components/screen/input';
// import DatePickerOne from '../components/screen/DatePickerOne';
import TableList from "../../components/List/TableList";
// import Select from '../components/screen/select';
import PagingList from "../../components/List/PagingList";
export default {
  data() {
    return {
      placeholder: "请输入手机号", //input框中的placehould
      content: "", //input收入值
      value: "", //单时间日期
      Bnumber: 10, //每页条数
      Pnumber: 1, //当前页数
      addNum: 0, //总共多少条数
      selectname: "", //下拉列表内容
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        }
      ], //列表数据
      listHeader: [], //列表的渲染部分
      datas: {}, //列表操作返回的数据
      type:'userlist',//列表标识
    };
  },
  components: {
    TableList,
    PagingList
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.userAdminList();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    let header_name = ["创建时间", "账户名", "账户身份", "用户姓名", "上次登录时间", "登录次数"]; //列表头部
    let list_content = ['add_time','account','role','real_name','last_time','login_count']; //列表渲染内容字段
    for (let key in this.tableData[0]) {
      list_content.push(key);
    }
    for (let i = 0; i < header_name.length; i++) {
      let obj = {
        label: header_name[i],
        prop: list_content[i]
      };
      this.listHeader.push(obj);
    }
    console.log(this.listHeader);
  },
  methods: {
    //获取input搜索值
    //   getChildinput (v) {
    //         this.content = v;
    //     },
    //获取单时间值
    // getChilddpone(e){
    //   this.value = e;
    // },
    //获取分页信息
    getChilddptwo(e) {
      this.Pnumber = e.Pnumber;
      this.Bnumber = e.Bnumber;
    },
    //获取下拉数据
    // getChilddpthree(e){
    //     this.selectname = e;
    // },
    //点击查询
    // query(){
    //     console.log(this.content + '' + this.value);
    // },
    //获取列表操作的数据
    operate(e) {
      this.datas = e;
      if (this.datas.type == "look") {
        //    跳转查看页面
      } else if (this.datas.type == "delect") {
      // 删除
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.$api
              .userAdminDel({
                token: this.publick.token(),
                id: this.datas.id
              })
              .then(res => {
                console.log(res);
                this.$message({
                  type: "success",
                  message: res.message
                });
                this.userAdminList();
              })
              .catch(res => {
                console.log(res);
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      }
    },
    userAdminList() {
      //获取用户列表
      this.$api
        .userAdminList({
          token: this.publick.token(),
          page: this.Pnumber,
          limit: this.Bnumber
        })
        .then(res => {
          console.log(res);
          this.tableData = res.data.data;
          this.addNum = res.data.total;
        })
        .catch(res => {
          console.log(res);
        });
    }
  },
  watch: {
    Bnumber(newval) {
      if (newval) {
        this.userAdminList();
      }
    },
    Pnumber(newval) {
      if (newval) {
        this.userAdminList();
      }
    }
  }
};
</script>
<style scoped>
/* @import url(); 引入css类 */
.list {
  width: 100%;
  height: 89vh;
  background: #fff;
  overflow-y: auto;
}
.ulist {
  background: #fff;
  width: 98%;
  margin: auto;
  margin-top: 2.5vh;
}
.screen {
  display: flex;
  height: 8vh;
  justify-content: flex-start;
  align-items: center;
}
.list_data {
  width: 98%;
  margin: auto;
  margin-top: 4vh;
}
.paging {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  margin-top: 4vh;
  padding-bottom: 2vh;
}
</style>